<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="../common/taglibs.jsp" %>
<%
    response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setDateHeader("Expires", 0);
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<jsp:include page="/page/common/include.jsp"></jsp:include>
<script language="javascript" type="text/javascript">

$(document).ready(function(){
	
	/** 初始化新增Panel位置 */
	$("#addPanel").offset({
		top:30,
		left:($(window).width()-500)*0.5
	});
	
	/** 初始化新增Panel */
	$("#addPanel").panel({
		width:500,
		height:400,
		onBeforeOpen:function(){
			/** 初始化资源信息下拉列表 */
			$("#role_resource").tree({
				animate:true,
				checkbox:true,
				cascadeCheck:true
			});
			$.ajax({
				url : '<%=request.getContextPath()%>/roleInfo/roleInfoAction!initRoleResource.do',
				type : 'post',
				dataType : 'text',
				cache : false,
				success : function(data) {
					$("#role_resource").tree('loadData',eval(data));
				}
			});
		}
	});
});

/**
 * 表单提交
 */
function formSubmit(){
	if(validateForm()){
		disableLinkButton();
		$.ajax({
			url : '<%=request.getContextPath()%>/roleInfo/roleInfoAction!addRoleInfo.do',
			type : 'post',
			data:{
				roleName:$("#roleInfo_roleName").val(),
				roleDesc:$("#roleInfo_roleDesc").val(),
				roleFuncs:getRoleFuncs()
			},
			dataType : 'text',
			cache : false,
			success : function(data) {
				enableLinkButton();
				var j = JSON.parse(data);
				if (j.result == 'success') {
					messageAlertInfo("操作结果",j.msg,formClear);
				} else {
					messageAlertError("操作结果",j.msg);
				}
			}
		});
	}
}

/**
 * 获取角色资源的值
 */
function getRoleFuncs(){
	var result = '';
	var funcs = $("#role_resource").tree("getChecked");
	if(funcs.length > 0){
		for(var i=0;i<funcs.length;i++){
			var funcCode = funcs[i].id;
			if(result == ''){
				result = funcCode;
			}else{
				result += "," + funcCode;
			}
		}
	}
	return result;
}

/**
 * 验证表单
 */
function validateForm(){
	return true;
}

/**
 * 清空表单的值
 */
function formClear(){
	goToPage('<%=request.getContextPath()%>/roleInfo/roleInfoAction!initAddRoleInfo.do');
}

</script>
</head>

<body style="background: white;" >
		<div id="addPanel" style="position:absolute;padding-top: 10px;padding-left:80px" >
				<form id="addForm">
			    	<table>
			    		<tr>
			    			<td>角色名称：</td>
			    			<td>
			    				<s:textfield name="roleInfo.roleName" />
			    			</td>
			    		</tr>
			    		<tr>
			    			<td>角色描述：</td>
			    			<td>
			    				<s:textfield name="roleInfo.roleDesc" />
			    			</td>
			    		</tr>
			    		<tr>
			    			<td>角色资源：</td>
			    			<td>
				    			<div style="height:290px;width:300px;overflow-y:auto;overflow-x:auto;" align="left">
				    				<ul id="role_resource" style="width:220px;"></ul>
				    			</div>
			    			</td>
			    		</tr>
			    		<tr>
			    			<td colspan="2" align="center">
			    				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="formSubmit()">提交</a>
								<a class="easyui-linkbutton" data-options="iconCls:'icon-reload'" href="javascript:void(0)" onclick="formClear()">清空</a>
			    			</td>
			    		</tr>
			    	</table>
		    	</form>
		</div>
</body>
</html>